package zipcode.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.sql.DataSource;

import zipcode.Util.DBUtil;
import zipcode.dto.Zipcode1DTO;

public class ZipCodeDAO1 {
	private DBUtil util;
	private static ZipCodeDAO1 instance;
	private ZipCodeDAO1(){
		util = DBUtil.getInstance();
	}
	public static ZipCodeDAO1 getInstance(){
		if(instance == null){
			instance = new ZipCodeDAO1();
		}
		return instance;
	}
	public int insertZipCode(Zipcode1DTO zdto) throws SQLException{
		Connection conn = null;
		PreparedStatement pstmt = null;
		String sql = "insert into zipcode(zipcode, zipcode_no, sido, gugun, dong, ri, doseo, bunji, building, zipcode_address)" +
				"values(?,?,?,?,?,?,?,?,?,?)";
		int cnt = 0;
		try{
			DataSource ds = util.getDataSource();
			conn = ds.getConnection();
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, zdto.getZipcode());
			pstmt.setString(2, zdto.getZipcodeNo());
			pstmt.setString(3, zdto.getSido());
			pstmt.setString(4, zdto.getGugun());
			pstmt.setString(5, zdto.getDong());
			pstmt.setString(6, zdto.getRi());
			pstmt.setString(7, zdto.getDoseo());
			pstmt.setString(8, zdto.getBunji());
			pstmt.setString(9, zdto.getBuilding());
			pstmt.setString(10, zdto.getZipcodeAddress());
			cnt = pstmt.executeUpdate();
		}finally{
			if(pstmt != null){
				try{
					pstmt.close();
				}catch(SQLException e){}
			}
			if(conn != null){
				try{
					conn.close();
				}catch(SQLException e){}
			}
		}
		return cnt;
	}
}














